EI balance in different CA1 neurons.¶

In [1]:
import sys
sys.path.append("../")
import glob
from Linearity import Neuron
import numpy as np
import scipy.stats as ss
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.font_manager import findfont, FontProperties
# print(plt.style.available)
plt.style.use('seaborn-white')
matplotlib.rcParams['font.family']
print(findfont(FontProperties(family=['sans-serif'])))
/usr/share/fonts/truetype/msttcorefonts/Arial.ttf
In [2]:
#Colorscheme for squares
color_sqr = matplotlib.cm.viridis(np.linspace(0,1,9))
In [5]:
voltageClampFiles = '/media/sahil/NCBS_Shares_BGStim/patch_data/voltage_clamp_files.txt'
In [6]:
with open (voltageClampFiles,'r') as r:
    dirnames = r.read().splitlines()
In [56]:
#Colorscheme for cells
color_cell = matplotlib.cm.plasma(np.linspace(0,1,len(dirnames)))
In [7]:
feature = 0
scalingFactor = 1e9
neurons = []
for dirname in dirnames:
    cellIndex = dirname.split('/')[-1]
    filename = dirname + '/plots/' + cellIndex + '.pkl'
    neurons.append(Neuron.load(filename))
In [55]:
f, ax = plt.subplots(1,3)
r_squared = []
slopes = []
for index, n in enumerate(neurons):
#     if index != (len(neurons) - 1) and index != (len(neurons) - 3) :
        obs_exc, obs_inh = {}, {}
        sqrs = []

        for expt in n:
            for sqr in expt:
                if (expt[sqr].type == 1):
                    sqrs.append(sqr)
                    for coord in expt[sqr].coordwise:
                        obs_exc[coord] = expt[sqr].coordwise[coord].average_feature[5]
                elif (expt[sqr].type == 2):
                    for coord in expt[sqr].coordwise:
                        obs_inh[coord] = expt[sqr].coordwise[coord].average_feature[0]

        exc, inh = [], []
        for coord in set(obs_exc).intersection(set(obs_inh)):
            exc.append(-obs_exc[coord]*scalingFactor)
            inh.append(obs_inh[coord]*scalingFactor)
            ax[0].scatter(-obs_exc[coord]*scalingFactor, obs_inh[coord]*scalingFactor, c=color_cell[index], s=10)
        
        
        slope, intercept, rval, pval, stderr = ss.linregress(exc, inh)
        r_squared.append(rval**2)
        slopes.append(slope)

        excRange = np.linspace(min(exc), max(exc), 100)
        inhFit = excRange*slope + intercept

        ax[0].plot(excRange, inhFit, c=color_cell[index])

    # xlim_old = ax[0].get_xlim()
    # ylim_old = ax[0].get_ylim()
    # minlim, maxlim = min(xlim_old[0], ylim_old[0]), max(xlim_old[1], ylim_old[1])
    # ax[0].set_xlim(minlim,maxlim)
    # ax[0].set_ylim(minlim,maxlim)
ax[0].set_title("Linear regression showing proportional E and I")
f.set_figheight(5)
f.set_figwidth(15)
#plt.legend(scatterPoints=sqrs, label=sqrs)
ax[1].hist(r_squared)
ax[1].set_title("$r^2$ for linear regression")
ax[2].hist(slopes)
ax[2].set_title("Different proportionality $P$ for E and I")
plt.show()
In [59]:
np.mean(r_squared), np.std(r_squared)
Out[59]:
(0.83586676553953665, 0.13098010092208628)
A. shows tight balance between tight balance between excitation and inhibition at the CA1 neuron. 
B. shows r-square for linear regression showing high degree of correlation between E and I. 
C. showing different proportionality P of all CA1 neurons.